package com.medical.admin.hospital.controller;

import com.medical.admin.hospital.common.dto.ComboDto;
import com.medical.admin.hospital.common.vo.*;
import com.medical.admin.hospital.service.ComboService;
import com.qf.medical.ex.BaseException;
import com.qf.medical.response.ResponseCode;
import com.qf.medical.response.ResponseEntity;
import com.qf.medical.up.aliyun.AliOSSUtilsAutoConfiguration;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.io.IOException;
/**
 * @description: 套餐信息管理
 * @author: LuAn
 * @date: 2024/4/28
 */
@Api(tags = "套餐管理Api在线文档")
@RestController
@RequestMapping("/combo")
public class ComboController {
    @Resource
    private ComboService comboService;

    @Resource
    private AliOSSUtilsAutoConfiguration aliOSSUtilsAutoConfiguration;

    @GetMapping("/page")
    @ApiOperation("分页查询套餐信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "comboType",value = "套餐类型"),
            @ApiImplicitParam(name = "comboTypeTitle", value = "套餐名称"),
            @ApiImplicitParam(name = "pageNum",value = "当前页"),
            @ApiImplicitParam(name = "pageSize",value = "页大小")})
    public ResponseEntity<PageVo<ComboVo>> list(String comboTypeName,String comboName, @RequestParam(defaultValue = "1")
    int pageNum, @RequestParam(defaultValue = "10") int pageSize){
        return ResponseEntity.success(comboService.list(comboTypeName,comboName,pageNum,pageSize));
    }

    @PostMapping("/add")
    @ApiOperation("新增套餐信息")
    @ApiImplicitParam(name = "comboDto",value = "套餐对象")
    public ResponseEntity<Integer> add(@RequestBody ComboDto comboDto){
        return ResponseEntity.success(comboService.insert(comboDto));
    }

    @ApiOperation("修改套餐信息")
    @PutMapping("/modify")
    @ApiImplicitParam(name = "comboDto" ,value = "套餐信息")
    public ResponseEntity<Integer> modify(@RequestBody ComboDto comboDto){
        return ResponseEntity.success(comboService.update(comboDto));
    }

    @ApiOperation("删除套餐信息")
    @DeleteMapping("/remove")
    @ApiImplicitParam(name = "comboId" ,value = "套餐ID")
    public ResponseEntity<Integer> remove(@NotNull Long comboId){
        return ResponseEntity.success(comboService.delete(comboId));
    }

    @ApiOperation("查询套餐详情")
    @GetMapping("/detail")
    @ApiImplicitParam(name = "comboId" ,value = "套餐ID")
    public ResponseEntity<ComboVo> detail(@NotNull Long comboId){
        return ResponseEntity.success(comboService.select(comboId));
    }

    @ApiOperation("下拉展示套餐类型信息")
    @GetMapping("/showComboType")
    public ResponseEntity<DownMenu> showDownMenu(){
        return ResponseEntity.success(comboService.selectComboType());
    }

    @ApiOperation("下拉展示医院信息")
    @GetMapping("/showHospital")
    public ResponseEntity<DownMenu> showHospital(){
        return ResponseEntity.success(comboService.selectHospital());
    }

    @ApiOperation("下拉展示项目信息")
    @GetMapping("/showProject")
    public ResponseEntity<DownMenu> showProject(){
        return ResponseEntity.success(comboService.selectProject());
    }

    @ApiOperation("套餐图片")
    @PostMapping("/upload")
    @ApiImplicitParam(name = "file",value = "文件上传对象")
    public String upload(@NotNull MultipartFile file){
        try {
            return aliOSSUtilsAutoConfiguration.upload(file);
        } catch (IOException e) {
            throw new BaseException(ResponseCode.SYS_ERROR);
        }
    }
}
